package com.etogc.groupchat.group.ui;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.etogc.groupchat.R;
import com.etogc.groupchat.group.biz.GroupHttpBiz;
import com.etogc.util.IntentHelper;
import com.etogc.util.StringUtil;
import com.etogc.util.YcToastHelper;

public class JoinGroupActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText etGroupID;
    private EditText etInviteCode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_join);
        etGroupID = findViewById(R.id.etGroupID);
        etInviteCode = findViewById(R.id.etInviteCode);
        ImageView ivBack = findViewById(R.id.ivBack);
        ivBack.setVisibility(View.VISIBLE);
        ivBack.setOnClickListener(this);
        ((TextView) findViewById(R.id.tvTitle)).setText("加入群聊");
        findViewById(R.id.btnJoin).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btnJoin:
                requestJoin();
                break;
            case R.id.ivBack:
                IntentHelper.finish(this);
                break;
        }
    }

    private void requestJoin() {
        String groupID = etGroupID.getText().toString();
        String inviteCode = etInviteCode.getText().toString();
        if (!StringUtil.isBlank(groupID) && !StringUtil.isBlank(inviteCode)) {
            GroupHttpBiz.joinGroup(this, groupID, inviteCode);
        } else {
            YcToastHelper.getInstance()._toast("请填写完整");
        }
    }
}
